package com.dm.saleassback.loginmanage.controller;

import com.dm.saleassback.loginmanage.service.LoginService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
@CrossOrigin
public class LoginController {
    @Autowired
    private LoginService loginService;

    @RequestMapping(value="/login",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> goIndex(@RequestBody Map<String,Object> param, HttpServletRequest request) throws SQLException {
        Map<String,Object> statusMap = loginService.queryUserInfosByUsername(param,request);
        return statusMap;
    }

    /**
         * @Description 初始化页面，查询所有中心店面
         * @Author zhangxue
         * @Date 8:53 2018/6/3
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/initPage",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String initPage( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(param.size()>=1){
            List<Map<String,Object>> resultList = loginService.queryAllSaleStore(param);
            resultMap.put("data",resultList);
            resultMap.put("status","1");
        }else{

            resultMap.put("status","0");
        }
        js = JSONObject.fromObject(resultMap);

        return js.toString();
    }

    /**
         * @Description 查询所有类别下拉框
         * @Author zhangxue
         * @Date 9:47 2018/6/3
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllCategorySelect",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllCategorySelect( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllCategorySelect(param);
        resultMap.put("data",resultList);
        return resultMap;
    }

    /**
     * @Description 查询所有项目下拉框
     * @Author zhangxue
     * @Date 9:47 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllProjectSelect",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllProjectSelect( @RequestBody Map<String,Object> param){
        JSONObject js = new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllProjectSelect(param);
        resultMap.put("data",resultList);
        return resultMap;
    }

    /**
     * @Description 查询所有岗位标准下拉框
     * @Author zhangxue
     * @Date 9:47 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllStandardSelect",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllStandardSelect( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllStandardSelect(param);
        resultMap.put("data",resultList);
        return resultMap;
    }

    /**
         * @Description 查询所有销售部员工
         * @Author zhangxue
         * @Date 15:27 2018/6/3
         * @Param
         * @retrun
         **/
    @RequestMapping(value="/queryAllSaleMan",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllSaleMan( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllSaleMan(param);
        resultMap.put("data",resultList);
        return resultMap;
    }

    /**
     * @Description 查询所有销售部员工下拉
     * @Author zhangxue
     * @Date 15:27 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllSaleManSelect",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllSaleManSelect( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllSaleManSelect(param);
        resultMap.put("data",resultList);
        return resultMap;
    }


    /**
     * @Description 查询所有销售部岗位
     * @Author zhangxue
     * @Date 15:27 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllSalePost",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllSalePost( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllSalePost(param);
        resultMap.put("data",resultList);
        return resultMap;
    }

    /**
     * @Description 查询所有销售部岗位下拉
     * @Author zhangxue
     * @Date 15:27 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllSalePostSelect",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllSalePostSelect( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllSalePostSelect(param);
        for(int i=0;i<resultList.size();i++){
            if(resultList.get(i).get("Post")==null){
                resultList.get(i).put("Post","其他");
            }
        }
        resultMap.put("data",resultList);
        return resultMap;
    }

    /**
     * @Description 查询所有销售部门店
     * @Author zhangxue
     * @Date 15:27 2018/6/3
     * @Param
     * @retrun
     **/
    @RequestMapping(value="/queryAllSaleStore",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> queryAllSaleStore( @RequestBody Map<String,Object> param){
        JSONObject js= new JSONObject();
        Map<String,Object> resultMap = new HashMap<String, Object>();
        List<Map<String,Object>> resultList = loginService.queryAllSaleStore(param);
        resultMap.put("data",resultList);
        return resultMap;
    }


}
